package com.snail.billing.session;

import org.json.JSONException;
import org.json.JSONObject;

import com.snail.billing.DataCache;
import com.snail.billing.json.JsonBase;
import com.snail.billing.net.BillingDataInfoHttpSession;
import com.snail.billing.net.BillingSecurity;

public class RegisterSquenceSession extends BillingDataInfoHttpSession {

	public RegisterSquenceSession() {
		DataCache cache = DataCache.getInstance();
		String host = cache.importParams.hostBusiness;
		String address = String.format("http://%s/fbi/ws/randompassport/queryRandomSquence.do", host);
		setAddress(address);
		buildParamPair();
	}

	@Override
	public BillingSecurity getSecurity() {
		if (DataCache.getInstance().isSandbox) {
			return BillingSecurity.securitySandbox2;
		}
		return BillingSecurity.security;
	}

	public static class JsonData extends JsonBase {

		private String userName;

		public JsonData(String jsonString) {
			super(jsonString);
			try {
				if (getCode() == 1) {
					JSONObject json = new JSONObject(jsonString);
					if (json.has("userName")) {
						userName = json.getString("userName");
					}
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

		public String getUserName() {
			return userName;
		}
	}

}
